package com.tom;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mysql.jdbc.Driver;

/**
 * Servlet implementation class VerifyServlet
 */
public class VerifyServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public VerifyServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                String vid = request.getParameter("vid");
                if (vid!=null){
                        try {
                                DriverManager.registerDriver(new Driver());
                                Connection conn = DriverManager.getConnection(
                                        "jdbc:mysql://j.snpy.org/j102", "jstu2", "abc123");
                                String sql = "UPDATE users SET vid=1 WHERE vid=?";
                                PreparedStatement pstmt = conn.prepareStatement(sql);
                                pstmt.setString(1, vid);
                                int rowCount = pstmt.executeUpdate();
                                if (rowCount==1){
                                        response.sendRedirect("verify_success.jsp");
                                }
                        } catch (SQLException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                        
                        
                        
                        
                }
                
        }

        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                // TODO Auto-generated method stub
        }

}